package edu.umd.ion.wavemeter.server;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import edu.umd.ion.wavemeter.service.PIDSettings;

@SuppressWarnings("serial")
@Entity(name = "PIDSettings")
@Table(name = "PIDSettings") //Name of the entity
@NamedQueries({
    @NamedQuery(name="AllPIDSettings",
        query="SELECT x FROM PIDSettings x")
})
public class PersistentPIDSettings implements Serializable, PersistentObject<Integer, PersistentPIDSettings> {
	@Id
	protected Integer Channel;
	protected double P, I, D, Ta, dt, Sensitivity;
	protected int DeviationUnit, SensitivityDimension;
	protected boolean UseTa, Constantdt, Polarity, AutoClearHistory, LockEnabled;
	protected String Course;
	protected int Serial;
	
	public void set(PIDSettings s) {
		Channel = s.Channel;
		P = s.P;
		I = s.I;
		D = s.D;
		Ta = s.Ta;
		dt = s.dt;
		Sensitivity = s.Sensitivity;
		DeviationUnit = s.DeviationUnit;
		SensitivityDimension = s.SensitivityDimension;
		UseTa = s.UseTa;
		Constantdt = s.Constantdt;
		Polarity = s.Polarity;
		AutoClearHistory = s.AutoClearHistory;
		Course = new String(s.Course);	
		Serial = s.Serial;
	}
	
	public void set(PersistentPIDSettings s) {
		Channel = s.Channel;
		P = s.P;
		I = s.I;
		D = s.D;
		Ta = s.Ta;
		dt = s.dt;
		Sensitivity = s.Sensitivity;
		DeviationUnit = s.DeviationUnit;
		SensitivityDimension = s.SensitivityDimension;
		UseTa = s.UseTa;
		Constantdt = s.Constantdt;
		Polarity = s.Polarity;
		AutoClearHistory = s.AutoClearHistory;
		Course = new String(s.Course);	
		Serial = s.Serial;
	}
	
	public PIDSettings plain() {
		PIDSettings o = new PIDSettings();
		o.Channel = Channel;
		o.P = P;
		o.I = I;
		o.D = D;
		o.Ta = Ta;
		o.dt = dt;
		o.Sensitivity = Sensitivity;
		o.DeviationUnit = DeviationUnit;
		o.SensitivityDimension = SensitivityDimension;
		o.UseTa = UseTa;
		o.Constantdt = Constantdt;
		o.Polarity = Polarity;
		o.AutoClearHistory = AutoClearHistory;
		o.Course = Course==null ? new String() : new String(Course);
		o.Serial = Serial;
		return o;		
	}

	public Integer getChannel() {
		return Channel;
	}

	public void setChannel(Integer channel) {
		Channel = channel;
	}

	@Override
	public Integer getPrimaryKey() {
		return Channel;
	}	
}
